package com.summer.data.table;

import com.summer.data.exception.BaseException;
import com.summer.data.type.Union2;

/**
 * @author 345480567@qq.com
 */
public class EntityUtils {

    public static Union2<Boolean, Class> isEntity(Object obj) {
        String canonicalName = obj.getClass().getCanonicalName();
        if (canonicalName.endsWith("."+BaseTable.ENTITY_CLASS_NAME)) {
            String tableClassName = canonicalName.substring(0, canonicalName.length()-BaseTable.ENTITY_CLASS_NAME.length()-1);
            Class<?> tableClass = null;
            try {
                tableClass = obj.getClass().getClassLoader().loadClass(tableClassName);
            } catch (ClassNotFoundException e) {
                throw new BaseException(e);
            }
            if (BaseTable.class.isAssignableFrom(tableClass)) {
                return Union2.create(true, tableClass);
            }
        }
        return Union2.create(false, null);
    }

    public static boolean isMemberChanged(Object obj, String memberName) {
        return true;
    }

    public static void set(Object obj, String memberName, Object value) {

    }

}
